class MyQueue {

    constructor(capacity) {
       this.front = null
       this.rear = null
       this.array = new Array(capacity)
    }

    enQueue(element) {
        if((this.rear + 1) % this.array.length === this.front) {
            throw new Error("队列已满")
        }
        this.array[this.rear] = element
        this.rear = (this.rear + 1) % this.array.length
    }

    deQueue() {
        if(this.rear === this.front) {
            throw new Error("队列已空")
        }
        let deQueueElement = this.array[this.front]
        this.front = (this.front + 1) % this.array.length
        return deQueueElement
    }

    output() {
        for (let i = this.front; i !== this.rear; i = (i+1) % this.array.length) {
            console.log(this.array[i])
        }
    }
}

let myQueue = new MyQueue(6)
myQueue.enQueue(3);
myQueue.enQueue(5);
myQueue.enQueue(6);
myQueue.deQueue();
myQueue.output();
